<template>
  <el-container>
    <el-header>
      <el-row type="flex" class="row-bg">
        <el-col :span="20">
          <div class="grid-content bg-purple title" style="text-align:left">
            电商后台管理系统
          </div>
        </el-col>
        <el-col :span="2">
          <div class="grid-content bg-purple-light" style="text-align:right; color: #eee">
            {{ getUsername }}
          </div>
        </el-col>
        <el-col :span="2">
          <div class="grid-content bg-purple" style="text-align:right">
            <el-button type="info" @click="logout">退出</el-button>
          </div>
        </el-col>
      </el-row>
    </el-header>
    <el-container>
      <left-menu></left-menu>
      <el-main>
        <!-- 其余页面都是home下的子组件,路由设置的时候使用children -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import leftMenu from "../../components/leftMenu.vue";
import { mapGetters } from "vuex"

export default {
 
  components: {
    leftMenu,
  },
  computed: {
    ...mapGetters(["getUsername"])
  },
  methods: {
    myMessage(type, text) {
      this.$message({
        type: type,
        message: text
      })
    },
    async logout() {
      let res = await this.$confirm("此操作将退出登录,是否继续?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).catch( () => {} )

      if(res != 'confirm') return this.myMessage('info', '取消操作')
      this.myMessage("success", "退出登录");
      this.$store.commit("clearToken");
      this.$router.replace({ path: "/login" })
    }
  }
};
</script>

<style scoped lang="less">
.el-header {
  background-color: rgb(55, 61, 65);
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  // text-align: center;
  // line-height: 160px;
  flex: 1;
}

body > .el-container {
  margin-bottom: 40px;
  display: flex;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.title {
  font-size: 20px;
  font-weight: bold;
  color: #fff;
}
</style>
